package com.ruoyi.boss.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.boss.domain.TDispatched;
import com.ruoyi.boss.service.ITDispatchedService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 待派单Controller
 * 
 * @author ruoyi
 * @date 2025-08-17
 */
@RestController
@RequestMapping("/dispatched")
public class TDispatchedController extends BaseController
{
    @Autowired
    private ITDispatchedService tDispatchedService;

    /**
     * 查询待派单列表
     */
    @RequiresPermissions("boss:dispatched:list")
    @GetMapping("/list")
    public TableDataInfo list(TDispatched tDispatched)
    {
        startPage();
        List<TDispatched> list = tDispatchedService.selectTDispatchedList(tDispatched);
        return getDataTable(list);
    }

    /**
     * 导出待派单列表
     */
    @RequiresPermissions("boss:dispatched:export")
    @Log(title = "待派单", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TDispatched tDispatched)
    {
        List<TDispatched> list = tDispatchedService.selectTDispatchedList(tDispatched);
        ExcelUtil<TDispatched> util = new ExcelUtil<TDispatched>(TDispatched.class);
        util.exportExcel(response, list, "待派单数据");
    }

    /**
     * 获取待派单详细信息
     */
    @RequiresPermissions("boss:dispatched:query")
    @GetMapping(value = "/{dispatchedId}")
    public AjaxResult getInfo(@PathVariable("dispatchedId") Long dispatchedId)
    {
        return success(tDispatchedService.selectTDispatchedByDispatchedId(dispatchedId));
    }

    /**
     * 新增待派单
     */
    @RequiresPermissions("boss:dispatched:add")
    @Log(title = "待派单", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TDispatched tDispatched)
    {
        return toAjax(tDispatchedService.insertTDispatched(tDispatched));
    }

    /**
     * 修改待派单
     */
    @RequiresPermissions("boss:dispatched:edit")
    @Log(title = "待派单", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TDispatched tDispatched)
    {
        return toAjax(tDispatchedService.updateTDispatched(tDispatched));
    }

    /**
     * 删除待派单
     */
    @RequiresPermissions("boss:dispatched:remove")
    @Log(title = "待派单", businessType = BusinessType.DELETE)
	@DeleteMapping("/{dispatchedIds}")
    public AjaxResult remove(@PathVariable Long[] dispatchedIds)
    {
        return toAjax(tDispatchedService.deleteTDispatchedByDispatchedIds(dispatchedIds));
    }
}
